package com.freeheart.validation.constraintvalidators.recent;


import java.time.LocalDateTime;

/**
 * 针对{@code java.time.LocalDateTime}类型的，计算距离今天的时间差
 *
 * @author: EmperorHeart
 * @date: 2025/5/10 1:24
 * @description
 */
public class ComputeGapForLocalDateTime implements ComputeGap {

    @Override
    public boolean support(Object obj) {
        return obj instanceof LocalDateTime;
    }

    @Override
    public long compute(Object obj, RecentProperties rp) {
        LocalDateTime dt = (LocalDateTime) obj;
        if (rp.isTruncate()) {
            return rp.currentUnit().between(dt.truncatedTo(rp.currentUnit()),
                    LocalDateTime.now().truncatedTo(rp.currentUnit()));
        }
        return rp.currentUnit().between(dt, LocalDateTime.now());
    }
}
